home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / bbsread / copymessage.br < prev    next >
Text File  |  1998-05-24  |  7KB  |  243 lines

  1. /*
  2. ** $VER: CopyMessage.br 1.2 (19.9.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** See SortMail.guide for documentation
  6. **
  7. */
  8.  
  9. options results
  10. options failat 31
  11.  
  12. parse arg arguments
  13.  
  14.  
  15. /*
  16. ** Initialize some variables
  17. */
  18.  
  19. version  = subword(sourceline(2), 4, 1)
  20.  
  21. template = 'SYSTEM/A,CONFERENCE/A,MSGNO/A,DESTCONF/A,DESTSYS/K,REPLYADDR/K'
  22.  
  23. CDB_MARK_OWN_MSGS      = 22           /* Also mark messages from user when adding messages. */
  24. CDF_NOT_ON_BBS         = '00008000'x  /* This conference is not on the bbs. */
  25.  
  26. CDNT_NONET             = 0  /* This conference is a local conference. This is the default values for new conferences. */
  27. CDNT_MAILFOLDER        = 3  /* This conference is a virtual mail folder */
  28.  
  29. MDB_READ               =  0  /* Message is read. */
  30. MDB_REPLIED            =  1  /* Message is replied. */
  31. MDB_PRIVATE            =  2  /* Message is private. */
  32. MDB_DELETED            =  5  /* Message is deleted. */
  33. MDB_KEEP               =  7  /* Keep message. Message will not be deleted during conference packing. */
  34. MDB_MARKED             = 10  /* Message is marked.  */
  35. MDB_URGENT             = 11  /* Message is urgent.    */
  36. MDB_IMPORTANT          = 12  /* Message is important. */
  37. MDB_SUPERMARKED        = 13  /* Message will not be unmarked as long as this flag is set. */
  38. MDB_CONFIDENTIAL       = 17  /* Message is confidential. */
  39.  
  40.  
  41. /*
  42. ** Find/open BBSREAD ARexx port
  43. */
  44.  
  45. if ~show('P', 'BBSREAD') then do
  46.     address(command)
  47.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  48.     if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
  49.     else 'WaitForPort BBSREAD'
  50.     if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
  51.     if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
  52.     end
  53.  
  54.  
  55. /*
  56. ** Give template if arguments = '?' or empty
  57. */
  58.  
  59. if (arguments = '?') | (arguments = '') then do
  60.     say 'Usage: 'template
  61.     say 'CopyMessage.br is an external script for SortMail.'
  62.     exit(5)
  63.     end
  64.  
  65. address(bbsread)
  66. 'READARGS "'template'" 'args' CMDLINE 'arguments
  67. if (rc ~= 0) then do
  68.     say BBSREAD.LASTERROR
  69.     say 'Template: 'template
  70.     say 'CopyMessage.br is an external script for SortMail.'
  71.     exit(5)
  72.     end
  73.  
  74.  
  75. /*
  76. ** Utilize BBSRead's copyback buffer
  77. */
  78.  
  79. address(bbsread)
  80. 'BUFMODE COPYBACK'
  81.  
  82. /*
  83. ** Read message's header and text stems, exit if it's deleted
  84. */
  85.  
  86. 'READBRMESSAGE "'args.SYSTEM'" "'args.CONFERENCE'" 'args.MSGNO' HEADSTEM 'head' DATASTEM 'data' TEXTSTEM 'text
  87. if (rc ~= 0) then signal error
  88.  
  89. if (bittst(data.FLAGS, MDB_DELETED)) then do; myerr = 'Message was deleted.'; rc = 20; signal error; end
  90.  
  91.  
  92. /*
  93. ** Create header for new message
  94. */
  95.  
  96. text.fromname = head.FROMNAME
  97. if (symbol('head.FROMADDR') = 'VAR')        then text.fromaddr        = head.FROMADDR
  98. if (symbol('head.TONAME') = 'VAR')          then text.toname          = head.TONAME
  99. if (symbol('head.TOADDR') = 'VAR')          then text.toaddr          = head.TOADDR
  100. if (symbol('head.MSGID') = 'VAR')           then text.msgid           = head.MSGID
  101. if (symbol('head.REFID') = 'VAR')           then text.refid           = head.REFID
  102. if (symbol('head.CREATIONDATE') = 'VAR')    then text.creationdate    = head.CREATIONDATE
  103. if (symbol('head.CREATIONDATETXT') = 'VAR') then text.creationdatetxt = head.CREATIONDATETXT
  104. if (symbol('head.SUBJECT') = 'VAR')         then text.subject         = head.SUBJECT
  105.  
  106. text.replyconf = args.CONFERENCE
  107.  
  108. /*
  109. ** Find a reply address from the arguments or the original message
  110. */
  111.  
  112. drop text.replyname
  113. if (symbol('args.REPLYADDR') ~= 'VAR') then do
  114.     if (symbol('text.REPLYADDR') ~= 'VAR') then do
  115.         text.replyaddr = head.FROMADDR
  116.         if (symbol('head.FROMNAME') = 'VAR') then text.replyname = head.FROMNAME
  117.         end
  118.     end
  119. else text.replyaddr = args.REPLYADDR
  120.  
  121.  
  122. /*
  123. ** Make sure args.DESTSYS contains something and get system configuration
  124. ** for destination
  125. */
  126.  
  127. if (symbol('args.DESTSYS') ~= 'VAR') then args.DESTSYS = args.SYSTEM
  128.  
  129. 'GETBBSDATA "'args.DESTSYS'" 'bbsdata
  130. if (rc ~= 0) then signal error
  131.  
  132.  
  133. /*
  134. ** See if the conference the msg will be written to exists
  135. */
  136.  
  137. 'GETCONFLIST BBSNAME "'args.DESTSYS'" STEM 'conflist
  138. if (rc ~= 0) then signal error
  139.  
  140. do n = 1 to conflist.COUNT + 1 while upper(args.DESTCONF) ~= upper(conflist.n)
  141.     if (n = conflist.COUNT + 1) then do
  142.         /* Create the new conference */
  143.         'CONFIGCONF "'args.DESTSYS'" "'args.DESTCONF'"'
  144.         if (rc ~= 0) then signal error
  145.  
  146.         'GETCONFDATA "'args.DESTSYS'" "'args.DESTCONF'" STEM 'confdata
  147.         if (rc ~= 0) then signal error
  148.  
  149.         if (confdata.CONFNETTYPE = CDNT_NONET) then do
  150.             'CONFIGCONF "'args.DESTSYS'" "'args.DESTCONF'" CONFNETTYPE 'CDNT_MAILFOLDER' SET 'c2x(CDF_NOT_ON_BBS)
  151.             if (rc ~= 0) then signal error
  152.         end
  153.     end
  154. end
  155.  
  156. drop conflist.
  157.  
  158.  
  159. /*
  160. ** Set the selected message flags
  161. */
  162.  
  163. writeflags = ''
  164. if (bittst(data.FLAGS, MDB_READ))         then writeflags = writeflags || 'READ '
  165. if (bittst(data.FLAGS, MDB_PRIVATE))      then writeflags = writeflags || 'PRIVATE '
  166. if (bittst(data.FLAGS, MDB_URGENT))       then writeflags = writeflags || 'URGENT '
  167. if (bittst(data.FLAGS, MDB_IMPORTANT))    then writeflags = writeflags || 'IMPORTANT '
  168. if (bittst(data.FLAGS, MDB_CONFIDENTIAL)) then writeflags = writeflags || 'CONFIDENTIAL '
  169.  
  170. updateflags = ''
  171. if (bittst(data.flags,  MDB_REPLIED))     then updateflags = updateflags || 'SETREPLIED '
  172. if (bittst(data.flags,  MDB_KEEP))        then updateflags = updateflags || 'SETKEEP '
  173. if (bittst(data.flags,  MDB_SUPERMARKED)) then updateflags = updateflags || 'SETSUPERUNREAD '
  174. if (symbol('data.HAZELEVEL') = 'VAR') & (data.HAZELEVEL > 0) then updateflags = updateflags || 'HAZELEVEL 'data.HAZELEVEL' '
  175.  
  176.  
  177. /*
  178. ** Mark message as unread only if Show own messages is not activated
  179. */
  180.  
  181. 'GETCONFDATA "'args.DESTSYS'" "'args.DESTCONF'" STEM 'confdata
  182. if (rc ~= 0) then signal error
  183.  
  184. if ~(bittst(confdata.FLAGS, CDB_MARK_OWN_MSGS)) & (upper(head.FROMADDR) = upper(bbsdata.EMAILADDR)) then writeflags = writeflags || 'DONTMARKMESSAGE '
  185.  
  186. /*
  187. ** Write the message
  188. */
  189.  
  190. address(bbsread)
  191. 'WRITEBRMESSAGE "'args.DESTSYS'" "'args.DESTCONF'" STEM 'text' 'writeflags
  192. if (rc ~= 0) then signal error
  193. msgnr = result
  194.  
  195.  
  196. /*
  197. ** If the new message's number is -1 then it was caught by a kill
  198. */
  199.  
  200. if (msgnr ~= -1) then do
  201.  
  202.     /*
  203.     ** Give the new message it's flags
  204.     */
  205.  
  206.     if (updateflags ~= '') then do
  207.         'UPDATEBRMESSAGE "'args.DESTSYS'" "'args.DESTCONF'" 'msgnr' 'updateflags
  208.         if (rc ~= 0) then signal error
  209.         end
  210.     end
  211.  
  212. returned = 0; signal cleanup
  213.  
  214.  
  215. /*
  216. ** Some error detection stuff
  217. */
  218.  
  219. error:
  220. syntax:
  221.  
  222. returned = rc
  223.  
  224. select
  225.     when symbol('BBSREAD.LASTERROR') = 'VAR' then say 'Line 'sigl' returned 'returned': 'BBSREAD.LASTERROR
  226.     when symbol('myerr') = 'VAR' then say 'Line 'sigl' returned 'returned': 'myerr
  227.     otherwise say 'Line 'sigl' returned 'returned': 'errortext(returned)
  228.     end
  229.  
  230. break_c:
  231. halt:
  232. cleanup:
  233.  
  234.  
  235. /*
  236. ** Turn off copyback buffer
  237. */
  238.  
  239. address(bbsread)
  240. 'BUFMODE ENDCOPYBACK'
  241.  
  242. exit(returned)
  243.